package com.itheima.controller;

import com.itheima.domain.Result;

import com.itheima.exception.BusinessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class CommonsExceptionAdvice {

       //捕获BusinessException异常
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e){
        //暂时打印到控制台
        e.printStackTrace();

        //将不合法信息告诉用户
        return new Result(false,e.getMessage());
    }




   @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
       //1.将异常信息保存到mysql或者redis或者日志文件中

       //2.通过微信公众号,手机短信,发送邮件等方式通知开发人员

       //暂时打印到控制台
       e.printStackTrace();

       //3.给用户响应一个友好的提示信息
       return new Result(false,"服务器正忙,请开通vip后再次尝试");
   }
}
